import multiprocessing
import logging
import sys
import time

logging.basicConfig(level=logging.INFO,format="%(name)s %(process)d %(processName)s %(thread)d %(message)s",stream=sys.stdout)
log = logging.getLogger(__name__)

def show(i):
    log.info("我启动了{}".format(i))

def worker(k):
    time.sleep(2)
    log.info("正在打印-{}".format(k))

if __name__ == "__main__":
    pool = multiprocessing.Pool(processes=2,initializer=show,initargs=(8,),maxtasksperchild=None)
    # # 如果改为maxtasksperchild=1每次线程执行worker时都会重新创建一个新的进程并执行show
    #pool = multiprocessing.Pool(processes=2, initializer=show, initargs=(8,), maxtasksperchild=1)
    time.sleep(3)
    for i in range(4):
        pool.apply(worker,args=(i+5,))
